package mazewar;

/**
 *
 * @author KeaneDCunha
 */
public class LamportClock {

    int timestamp;
    int pid;

    public LamportClock(int pid) {
        this.pid = pid;
        timestamp = 1;
    }

    public int getTimeStamp() {
        return timestamp;
    }

    public int getProcessID(){
        return pid;
    }

    public int updateTimeStamp(LamportClock other){

        if(timestamp < other.getTimeStamp()){
            timestamp = other.getTimeStamp();
        }

        // tie breaker - unique pid
        else if(timestamp == other.getTimeStamp() && pid < other.getProcessID()){
            timestamp = other.getTimeStamp();
        }

        incrementTimeStamp();
        
        return timestamp;
    }

    public void incrementTimeStamp() {
        timestamp += 1;
    }
//
//    public void sendMessage() {
//        timestamp += 1;
//        //ToDo: sendMessage including timestamp
//    }
//
//    public void receiveMessage(int timestampReceived) {
//        timestamp = Math.max(timestamp, timestampReceived) + 1;
//    }
}
